home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14436 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  124 lines

  1. Path: news.platinum.com!news
  2. From: Chris Harris <Chris@harrisoft.mv.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: STL An VC++ 4.1
  5. Date: Thu, 28 Mar 1996 10:47:28 -0500
  6. Organization: Harrisoft Inc.
  7. Message-ID: <315AB490.1863@harrisoft.mv.com>
  8. NNTP-Posting-Host: ns2-ssn.platinum.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13.  
  14. I have run into what looks like a problem with the Microsoft 
  15. compiler.  
  16.  
  17. This code sample run fine under Visual Age under OS/2, but under 
  18. Windows NT when compiled with MSVC 4.1 it crashes 
  19. intermittently.
  20.  
  21. You may have to run it with a parameter of 100 5 times before it 
  22. crashes, but it will crash.  
  23.  
  24. Has anyone else had a similar problem?
  25.  
  26. Regards,
  27.  
  28. Chris Harris
  29.  
  30. Chris@harrisoft.mv.com
  31.  
  32. ------------------------------------------------
  33.  
  34. /// begin test.cpp
  35.  
  36. #define NOMINMAX
  37. #include <map.h>
  38. #include <stdio.h>
  39.  
  40.  
  41. typedef int BOOL;
  42. typedef unsigned long DWORD;
  43.  
  44.  
  45. #ifdef _WIN32
  46. #define _Optlink
  47. #endif
  48.  
  49. #ifdef __BORLANDC__
  50. #define _Optlink
  51. #endif
  52.  
  53.  
  54. #include <process.h>
  55.  
  56.  
  57. DWORD BeginThread(void ( * _Optlink start )( void * ), void* 
  58. Info )
  59. {
  60.    DWORD dwThread = (DWORD)-1;
  61.    #ifdef _WIN32
  62.       dwThread = _beginthread(start,1024* 20,Info);
  63.    #elif defined __BORLANDC__
  64.       dwThread = _beginthread(start,1024 * 20,Info);
  65.    #else
  66.       dwThread = _beginthread(start,NULL, 1024 * 8,Info);
  67.    #endif
  68.  
  69.    return ( dwThread );
  70. }
  71.  
  72. typedef map <int,int*,less<int> > TestMap;
  73.  
  74. extern "C"
  75. {
  76.    void RunTest(void*);
  77. }
  78.  
  79.  
  80. DWORD dwCount = 0;
  81. int main(int argc, char** argv )
  82. {
  83.    if ( 1 == argc )
  84.    {
  85.       printf( "Run with a number parameter" );
  86.       return ( 0 );
  87.    }
  88.  
  89.    for(int i =0; i < atoi(argv[1]); i++)
  90.    { 
  91.       BeginThread(RunTest,NULL);
  92.    }
  93.  
  94.   return ( 0 );
  95. }
  96.  
  97.  
  98.  
  99. void RunTest(void*)
  100. {   
  101.    
  102.    int* p1;
  103.    int* p2;
  104.    int* p3;
  105.    
  106.    {
  107.       TestMap Map;      
  108.  
  109.       p1 = new int ( 1 );
  110.       p2 = new int ( 2 );
  111.       p3 = new int ( 3 );
  112.  
  113.       Map[1] = p1;
  114.       Map[2] = p2;
  115.       Map[3] = p3;
  116.    }
  117.    // Now Map is out of scope
  118.    // so we can delete the integers
  119.    delete p1;
  120.    delete p2;
  121.    delete p3;
  122.    
  123. }
  124.